#include<bits/stdc++.h>
#define int long long
#define N 3005
using namespace std;
int n,k;
int cnt,vis[N][N],t[N][N],e[N][N];
int viss[N][N],z;
int A[4]={1,0,-1,0},B[4]={0,1,0,-1};
char s[N][N];
const int mod=1e9+7,inv2=500000004,inv6=166666668,inv24=41666667;
int Pow(int x,int y){
    x%=mod;
    int z=1;
    while(y){
        if(y&1) z=z*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return z;
}
void sub1(){
    printf("%lld\n",cnt%mod);
}
void sub2(){
    int ans=cnt*(cnt-1)/2;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(vis[i][j]==1) ans+=(!vis[i+1][j])+(!vis[i-1][j])+(!vis[i][j+1])+(!vis[i][j-1]);
    printf("%lld\n",ans%mod);
}
void sub3(){
    int ans=cnt*(cnt-1)%mod*(cnt-2)%mod*inv6%mod;
    int sum=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++) t[i][j]=(vis[i+1][j]==1)+(vis[i-1][j]==1)+(vis[i][j+1]==1)+(vis[i][j-1]==1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++) e[i][j]=(vis[i+1][j]==0)+(vis[i-1][j]==0)+(vis[i][j+1]==0)+(vis[i][j-1]==0);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(vis[i][j]!=1) continue;
            ans=(ans+e[i][j]*(e[i][j]-1)/2)%mod;
            for(int k=0;k<4;k++){
                if(vis[i+A[k]][j+B[k]]!=0) continue;
                ans=(ans+cnt-t[i+A[k]][j+B[k]]+mod)%mod;
                sum=(sum+t[i+A[k]][j+B[k]]-1+mod)%mod;
                ans=(ans+e[i+A[k]][j+B[k]])%mod;
            }
        }
    }
    ans=(ans+sum*inv2%mod)%mod;
    printf("%lld\n",ans);
}
void add(int x,int y,int k){
    for(int i=0;i<4;i++){
        if(vis[x+A[i]][y+B[i]]!=1) continue;
        if(viss[x+A[i]][y+B[i]]==0) z++;
        viss[x+A[i]][y+B[i]]+=k;
        if(viss[x+A[i]][y+B[i]]==0) z--;
    }
}
void sub4(){
    int ans=cnt*(cnt-1)%mod*(cnt-2)%mod*(cnt-3)%mod*inv24%mod;//1
    int c=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++) t[i][j]=(vis[i+1][j]==1)+(vis[i-1][j]==1)+(vis[i][j+1]==1)+(vis[i][j-1]==1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++) e[i][j]=(vis[i+1][j]==0)+(vis[i-1][j]==0)+(vis[i][j+1]==0)+(vis[i][j-1]==0);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(vis[i][j]!=1) continue;
            ans=(ans+c*e[i][j]%mod)%mod;//3
            ans=(ans+(e[i][j]==3))%mod;//7
            c+=e[i][j];
            for(int k=0;k<4;k++){
                if(vis[i+A[k]][j+B[k]]!=0) continue;
                add(i+A[k],j+B[k],1);
                for(int l=0;l<4;l++){
                    if(vis[i+A[k]+A[l]][j+B[k]+B[l]]!=0) continue;
                    add(i+A[k]+A[l],j+B[k]+B[l],1);
                    ans=(ans+cnt-z)%mod;//4
                    add(i+A[k]+A[l],j+B[k]+B[l],-1);
                    for(int m=0;m<4;m++){
                        if(vis[i+A[k]+A[l]+A[m]][j+B[k]+B[l]+B[m]]!=0||(A[l]+A[m]==0&&B[l]+B[m]==0)) continue;
                        ans=(ans+1)%mod;//8
                    }
                    for(int m=0;m<4;m++){
                        if(vis[i+A[m]][j+B[m]]!=0||m==k) continue;
                        ans=(ans+1)%mod;//9
                    }
                }
                for(int l=k+1;l<4;l++){
                    if(vis[i+A[l]][j+B[l]]!=0) continue;
                    add(i+A[l],j+B[l],1);
                    ans=(ans+cnt-z)%mod;//6
                    add(i+A[l],j+B[l],-1);
                }
                add(i+A[k],j+B[k],-1);
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(vis[i][j]!=0) continue;
            if(t[i][j]==3) ans=(ans+1+mod)%mod;
            if(t[i][j]==4) ans=(ans+4+mod)%mod;//2-2
            ans=(ans-(t[i][j]*(t[i][j]-1)/2)%mod*(cnt-2)%mod+mod)%mod;//2-1
            ans=(ans+t[i][j]*(cnt-1)%mod*(cnt-2)%mod*inv2%mod)%mod;//2
            ans=(ans-(t[i][j]*(t[i][j]-1)/2)%mod+mod)%mod;//3-1
            ans=(ans+(t[i][j]*(t[i][j]-1)/2)%mod*e[i][j]%mod)%mod;//5
        }
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<n;j++){
            if(vis[i][j]+vis[i][j+1]+vis[i+1][j]+vis[i+1][j+1]==1) ans=(ans-3+mod)%mod;//8/9
            if(vis[i][j]==1&&vis[i+1][j+1]==1&&vis[i+1][j]==0&&vis[i][j+1]==0) ans=(ans-1+mod)%mod;
            if(vis[i][j]==0&&vis[i+1][j+1]==0&&vis[i+1][j]==1&&vis[i][j+1]==1) ans=(ans-1+mod)%mod;//3-2
        }
    }
    printf("%lld\n",ans);
}
signed main(){
    freopen("brick.in","r",stdin);
    freopen("brick.out","w",stdout);
    scanf("%lld %lld",&n,&k);
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++) vis[0][i]=vis[i][0]=vis[n+1][i]=vis[i][n+1]=2;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(s[i][j]=='#') vis[i][j]=2;
            else if(s[i+1][j]=='#'||s[i-1][j]=='#'||s[i][j+1]=='#'||s[i][j-1]=='#') vis[i][j]=1,cnt++;
        }
    }  
    if(k==1){sub1();return 0;}
    if(k==2){sub2();return 0;}
    if(k==3){sub3();return 0;}
    if(k==4){sub4();return 0;}
    return 0;
}